import Vue from 'vue'
import store from '@/store'
import { isString, isArray } from './util.js'
import $ from '@/common/base.js'


function checkNeed() {
  const env = process.env.NODE_ENV
  return env === 'production'
}

if (checkNeed()) {
  Vue.config.errorHandler = function(err, vm, info, a) {
  // Don't ask me why I use Vue.nextTick, it just a hack.
  // detail see https://forum.vuejs.org/t/dispatch-in-vue-config-errorhandler-has-some-problem/23500
	Vue.nextTick(() => {
			store.dispatch('errorLog/addErrorLog', {
				err,
				vm,
				info,
				url: $.getCurrentPage().route
			})
			console.error(err, info)
    })
  }
}
